﻿<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ucApplication1.ascx.vb" Inherits="RWN.ucApplication1" %>
<%@ Register Assembly="NumericTextBox" Namespace="NumericTextBoxControl" TagPrefix="cc1" %>
<%@ Register Assembly="Sarayut.ControlLibrary" Namespace="Sarayut.ControlLibrary" TagPrefix="cc2" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="True">
</asp:ScriptManager>
<asp:Literal ID="ltrJS" runat="server"></asp:Literal>
<script language="JavaScript">

	function ChangFormatID_OnFocus(txtbox) {
		var lastCurPos = GetCursorLocation(txtbox);
		txtbox.value = txtbox.value.replace('-', '');

		if (document.selection) { //IE
			// Set focus on the element
			txtbox.focus();

			// Create empty selection range
			var oSel = document.selection.createRange();

			// Move selection start and end to 0 position
			oSel.moveStart('character', -txtbox.value.length);

			// Move selection start and end to desired position
			oSel.moveStart('character', lastCurPos);
			oSel.moveEnd('character', 0);
			oSel.select();

		}
		else if (txtbox.selectionStart || txtbox.selectionStart == '0') {//Firefox
			txtbox.selectionStart = 0;
			txtbox.selectionEnd = lastCurPos;
			txtbox.focus();
		}

	}

	function GetCursorLocation(CurrentTextBox) {
		var CurrentSelection, FullRange, SelectedRange, LocationIndex = -1;
		if (typeof CurrentTextBox.selectionStart == "number") {
			LocationIndex = CurrentTextBox.selectionStart;
		}
		else if (document.selection && CurrentTextBox.createTextRange) {
			CurrentSelection = document.selection;
			if (CurrentSelection) {
				SelectedRange = CurrentSelection.createRange();
				FullRange = CurrentTextBox.createTextRange();
				FullRange.setEndPoint("EndToStart", SelectedRange);
				LocationIndex = FullRange.text.length;
			}
		}
		return LocationIndex;
	}

	function calculate_age(birth_month, birth_day, birth_year) {
		today_date = new Date();
		today_year = today_date.getFullYear();
		today_month = today_date.getMonth();
		today_day = today_date.getDate();
		age = today_year - birth_year;
		if (today_month < (birth_month - 1)) { age--; }

		if (((birth_month - 1) == today_month) && (today_day < birth_day)) { age--; }
		return age;
	}

	function AlertUnder18Age() {
		var bdDate;
		bdDate = document.getElementById(brithdayID).value;

		if (bdDate != "") {
			try {
				var splitResult = bdDate.split("/");

				if (calculate_age(splitResult[1], splitResult[0], (splitResult[2] - 543)) <= 20) {
					alert("กรณีอายุของผู้สมัครตั้งแต่ 18 ปีขึ้นไปแต่ไม่ถึง 20 ปีบริบูรณ์\r\nกรุณาแนบสำเนาบัตรประชาชนและทะเบียนบ้านของผู้ปกครอง\r\nพร้อมทั้งเซ็นรับรองสำเนาในเอกสารทุกใบ และในใบสมัคร");
				}

			}
			catch (err) {

			}

		}

	}

	function checkID(id) {
		if (id.length != 13) return false;
		for (i = 0, sum = 0; i < 12; i++)
			sum += parseFloat(id.charAt(i)) * (13 - i); if ((11 - sum % 11) % 10 != parseFloat(id.charAt(12)))
			return false; return true;
	}

	function checkIDCard(sender, args) {
	    var ddlCardType = document.getElementById("ctl00_ContentPlaceHolder1_ucApplication11_ddlCardType");
	    var CardType = ddlCardType.options[ddlCardType.selectedIndex].value;
	    var val = document.getElementById(cardID).value.replace('-', '');
	    if (CardType != "PID") {
	        args.IsValid = true;
	        return;
	    }
	    if (val.length != 13) {
	        args.IsValid = false;
	        return;
	    }
	    if (checkID(val)) {
	        args.IsValid = true;
	        return;
	    } else {
	        args.IsValid = false;
	        return;
	    }
	}

	function ChangFormatID() {
		var val = document.getElementById(appID).value.replace('-', '');
		if (val.length != 10) {
			return;
		}
		document.getElementById(appID).value = val.substr(0, 2) + '-' + val.substr(2, 8);
	}

	function ValidateID(sender, args) {

		var val = document.getElementById(appID).value.replace('-', '');

		if (val == "") {
			args.IsValid = false;
			return;
		}

		if (val.length != 10) {
			args.IsValid = false;
			return;
		}

		document.getElementById(appID).value = val.substr(0, 2) + '-' + val.substr(2, 8);
		args.IsValid = true;
	}

	function ValidateBirthDate(sender, args) {

		if (document.getElementById(brithdayID).value == "") {
			args.IsValid = false;
			return;
		}
		args.IsValid = true;
	}

	function ValidateCardDate(sender, args) {
		if (document.getElementById(carddayID).value == "" && document.getElementById("ctl00_ContentPlaceHolder1_ucApplication11_OFFICER_CARD_EXPIREDATE_TYPE_0").checked == true) {
			args.IsValid = false;
			return;
		}
		args.IsValid = true;
	}

	function ValidateCardTypeDesc(sender, args) {
	    var ddlCardType = document.getElementById("ctl00_ContentPlaceHolder1_ucApplication11_ddlCardType");
	    var CardType = ddlCardType.options[ddlCardType.selectedIndex].value;

	    if (CardType == "OTH") {
	        if (document.getElementById(cardTypeDesc).value == "") {
	            args.IsValid = false;
	            return;
	        }
	    }

	    args.IsValid = true;
	}

</script>
<table cellpadding="0" cellspacing="0" style="width: 100%;" class="profile" bgcolor="White">
	<tr>
		<td bgcolor="#E0E0E0" width="20%">
			เลขที่ใบสมัคร / รหัสนักธุรกิจ *:
		</td>
		<td>
			<cc1:NumericTextBox ID="OFFICER_APP_ID" runat="server" AllowZero="False" ControlMode="Text"
				DecimalSeparator="None" MaxLength="10" ThousandsSeparator="None" />
			<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="OFFICER_APP_ID"
				ErrorMessage="กรุณาระบุเลขที่ใบสมัคร / รหัสนักธุรกิจ" ValidationGroup="Reg1">*</asp:RequiredFieldValidator>
			<asp:CustomValidator ID="CustomValidator3" runat="server" ClientValidationFunction="ValidateID"
				ControlToValidate="OFFICER_APP_ID" Display="Dynamic" ErrorMessage="กรุณาระบุเลขที่ใบสมัคร / รหัสนักธุรกิจให้ถูกต้อง"
				ValidationGroup="Reg1">*</asp:CustomValidator>
		</td>
		<td bgcolor="#E0E0E0" width="20%">
			หมายเลขโทรศัพท์<br />
			ในการทำธุรกิจ *:
		</td>
		<td>
			<cc1:NumericTextBox ID="OFFCIER_APP_TEL" runat="server" AllowZero="False" ControlMode="Text"
				DecimalSeparator="None" MaxLength="10" ThousandsSeparator="None" />
			<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="OFFCIER_APP_TEL"
				ErrorMessage="กรุณาระบุหมายเลขโทรศัพท์" ValidationGroup="Reg1">*</asp:RequiredFieldValidator>
			<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="OFFCIER_APP_TEL"
				Display="Dynamic" ErrorMessage="หมายเลขโทรศัพท์ในการทำธุรกิจไม่ถูกต้อง" ValidationExpression="[0-9]{10,}"
				ValidationGroup="Reg1">*</asp:RegularExpressionValidator>
		</td>
	</tr>
	<tr>
		<td bgcolor="#E0E0E0" width="20%">
			ชื่อ (ไทย) *:
		</td>
		<td>
			<asp:TextBox ID="OFFICER_FIRSTNAME_THA" runat="server" MaxLength="255" Width="200px"></asp:TextBox>
			<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="OFFICER_FIRSTNAME_THA"
				ErrorMessage="กรุณาระบุชื่อ (ไทย)" ValidationGroup="Reg1">*</asp:RequiredFieldValidator>
		</td>
		<td bgcolor="#E0E0E0" width="20%">
			นามสกุล (ไทย) *:
		</td>
		<td>
			<asp:TextBox ID="OFFICER_LASTNAME_THA" runat="server" MaxLength="255" Width="200px"></asp:TextBox>
			<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="OFFICER_LASTNAME_THA"
				ErrorMessage="กรุณาระบุนามสกุล (ไทย)" ValidationGroup="Reg1">*</asp:RequiredFieldValidator>
		</td>
	</tr>
	<tr>
		<td bgcolor="#E0E0E0" width="20%">
			Name :
		</td>
		<td>
			<asp:TextBox ID="OFFICER_FIRSTNAME_ENG" runat="server" MaxLength="255" Width="200px"></asp:TextBox>
		</td>
		<td bgcolor="#E0E0E0" width="20%">
			Surname :
		</td>
		<td>
			<asp:TextBox ID="OFFICER_LASTNAME_ENG" runat="server" MaxLength="255" Width="200px"></asp:TextBox>
		</td>
	</tr>
	<tr>
		<td bgcolor="#E0E0E0" width="20%">
			เพศ:
		</td>
		<td>
			<asp:RadioButtonList ID="OFFICER_SEX" runat="server" RepeatDirection="Horizontal"
				RepeatLayout="Flow">
				<asp:ListItem Value="M">ชาย</asp:ListItem>
				<asp:ListItem Value="F">หญิง</asp:ListItem>
			</asp:RadioButtonList>
			<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="OFFICER_SEX"
				ErrorMessage="กรุณาระบุเพศ" ValidationGroup="Reg1">*</asp:RequiredFieldValidator>
		</td>
		<td bgcolor="#E0E0E0" width="20%">
			&nbsp;
		</td>
		<td>
			&nbsp;
		</td>
	</tr>
	<tr>
		<td bgcolor="#E0E0E0" width="20%">
			ประเภทบัตร: 
		</td>
		<td>

			<asp:DropDownList ID="ddlCardType" runat="server" AutoPostBack="True">
				<asp:ListItem Value="PID" Selected="True">บัตรประชาชน</asp:ListItem>
				<asp:ListItem Value="CID">บัตรนิติบุคคล</asp:ListItem>
                <asp:ListItem Value="FID">บัตรคนต่างชาติ</asp:ListItem>
                <asp:ListItem Value="OTH">บัตรอื่นๆ</asp:ListItem>
			</asp:DropDownList>

		</td>
		<td bgcolor="#E0E0E0" width="20%">
			กรณีเลือกประเภทบัตรอื่นๆ<br />
            กรุณาระบุชนิดของบัตร:</td>
		<td class="rnwCSS">


			<asp:TextBox ID="OFFICER_CARD_TYPE_DESC" runat="server" MaxLength="255" 
                Width="200px" Enabled="False"></asp:TextBox>
		    <asp:CustomValidator ID="cvOfficerCardTypeDesc" runat="server" ErrorMessage="กรุณาระบุชนิดของบัตร"
			    ClientValidationFunction="ValidateCardTypeDesc" ValidationGroup="Reg1" Display="Dynamic">*</asp:CustomValidator>
		</td>
	</tr>
	<tr>
		<td bgcolor="#E0E0E0" width="20%">
			<asp:Label ID="lblCardType" runat="server" Text="เลขที่บัตรประชาชน *:"></asp:Label>
		</td>
		<td>
			<asp:TextBox ID="OFFICER_CARD_NO" runat="server" MaxLength="16" Width="200px"></asp:TextBox>
			<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="OFFICER_CARD_NO"
				ErrorMessage="กรุณาระบุเลขที่บัตรประชาชน/นิติบุคคล/คนต่างชาติ/อื่นๆ" ValidationGroup="Reg1" Display="Dynamic">*</asp:RequiredFieldValidator>
            <%--			<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="OFFICER_CARD_NO"
				Display="Dynamic" ErrorMessage="เลขที่บัตรประชาชนไม่ถูกต้อง" ValidationExpression="[0-9]{13,}"
				ValidationGroup="Reg1">*</asp:RegularExpressionValidator>--%>
			<asp:CustomValidator ID="CustomValidator4" runat="server" ClientValidationFunction="checkIDCard"
				ControlToValidate="OFFICER_CARD_NO" Display="Dynamic" ErrorMessage="เลขที่บัตรประชาชนไม่ถูกต้อง"
				ValidationGroup="Reg1">*</asp:CustomValidator>
		</td>
		<td bgcolor="#E0E0E0" width="20%">
			วันเกิดตามบัตร *:
		</td>
		<td class="rnwCSS">
		<!--
			<table cellpadding="0" cellspacing="0">
				<tr>
					<td>
						<%--<cc2:CalendarControl ID="OFFICER_BIRTHDATE" runat="server" ThaiMode="True" />--%>
					</td>
					<td>
						<%--<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="กรุณาระบุวันเกิดตามบัตร"
							ClientValidationFunction="ValidateBirthDate" ValidationGroup="Reg1">*</asp:CustomValidator>--%>
					</td>
				</tr>
			</table>
			-->
			<asp:TextBox ID="OFFICER_BIRTHDATE" runat="server" Width="70px"></asp:TextBox><asp:ImageButton ID="ibtnOFFICER_BIRTHDATE" runat="server" ImageUrl="~/images/Calendar.gif" />
			<asp:CalendarExtender ID="OFFICER_BIRTHDATE_CalendarExtender" runat="server" 
				CssClass="" Enabled="True" Format="dd/MM/yyyy" 
				PopupButtonID="ibtnOFFICER_BIRTHDATE" TargetControlID="OFFICER_BIRTHDATE">
			</asp:CalendarExtender>			
			 <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" 
            ControlToValidate="OFFICER_BIRTHDATE" ErrorMessage="ท่านระบุรูปแบบวันที่ไม่ถูกต้อง (วว/ดด/ปปปป)" 
            ValidationExpression="^\d{2}\/\d{2}\/\d{4}$" ValidationGroup="Reg1" 
				Display="Dynamic">*</asp:RegularExpressionValidator>
						<asp:RequiredFieldValidator
							ID="RequiredFieldValidator5" runat="server" ErrorMessage="กรุณาระบุวันเกิดตามบัตร"
							ClientValidationFunction="ValidateBirthDate" ValidationGroup="Reg1" 
				ControlToValidate="OFFICER_BIRTHDATE" Display="Dynamic">*</asp:RequiredFieldValidator>
				<span class="tooltip_label">วัน/เดือน/ปีพ.ศ. เช่น 01/01/2500</span>
		</td>
	</tr>
	<tr>
		<td bgcolor="#E0E0E0" width="20%">
			บัตรหมดอายุ:
		</td>
		<td>
			<asp:RadioButtonList ID="OFFICER_CARD_EXPIREDATE_TYPE" runat="server" RepeatDirection="Horizontal"
				RepeatLayout="Flow">
				<asp:ListItem Value="Y">มีวันหมดอายุ</asp:ListItem>
				<asp:ListItem Value="N">ตลอดชีพ</asp:ListItem>
			</asp:RadioButtonList>
			<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="OFFICER_CARD_EXPIREDATE_TYPE"
				ErrorMessage="กรุณาระบุชนิดบัตร" ValidationGroup="Reg1">*</asp:RequiredFieldValidator>
		</td>
		<td bgcolor="#E0E0E0" width="20%">
			วันบัตรหมดอายุ :
		</td>
		<td class="rnwCSS">
		<!--
			<table cellpadding="0" cellspacing="0">
				<tr>
					<td>
						<%--<cc2:CalendarControl ID="OFFICER_CARD_EXPIREDATE" runat="server" ThaiMode="True" />--%>
					</td>
					<td>
						<%--<asp:CustomValidator ID="CustomValidator2" runat="server" ErrorMessage="กรุณาระบุวันบัตรหมดอายุ"
							ClientValidationFunction="ValidateCardDate" ValidationGroup="Reg1">*</asp:CustomValidator>--%>
					</td>
				</tr>
			</table>
			-->
			<asp:TextBox ID="OFFICER_CARD_EXPIREDATE" runat="server" Width="70px"></asp:TextBox><asp:ImageButton ID="ibtnOFFICER_CARD_EXPIREDATE" runat="server" ImageUrl="~/images/Calendar.gif" />
			<asp:CalendarExtender ID="CalendarExtender1" runat="server" 
				CssClass="" Enabled="True" Format="dd/MM/yyyy" 
				PopupButtonID="ibtnOFFICER_CARD_EXPIREDATE" TargetControlID="OFFICER_CARD_EXPIREDATE">
			</asp:CalendarExtender>			
			 <asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" 
            ControlToValidate="OFFICER_CARD_EXPIREDATE" ErrorMessage="ท่านระบุรูปแบบวันที่ไม่ถูกต้อง (วว/ดด/ปปปป)" 
            ValidationExpression="^\d{2}\/\d{2}\/\d{4}$" ValidationGroup="Reg1" 
				Display="Dynamic">*</asp:RegularExpressionValidator>
				<asp:CustomValidator ID="CustomValidator2" runat="server" ErrorMessage="กรุณาระบุวันบัตรหมดอายุ"
							ClientValidationFunction="ValidateCardDate" ValidationGroup="Reg1" Display="Dynamic">*</asp:CustomValidator>
							<span class="tooltip_label">วัน/เดือน/ปีพ.ศ. เช่น 01/01/2500</span>
		</td>
	</tr>
	<tr>
		<td bgcolor="#E0E0E0" width="20%">
			สถานะภาพ:
		</td>
		<td>
			<asp:RadioButtonList ID="OFFICER_MARRIED_STATUS" runat="server" RepeatDirection="Horizontal"
				RepeatLayout="Flow">
				<asp:ListItem Value="S">โสด</asp:ListItem>
				<asp:ListItem Value="M">สมรส</asp:ListItem>
			</asp:RadioButtonList>
			<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ControlToValidate="OFFICER_MARRIED_STATUS"
				ErrorMessage="กรุณาระบุสถานะภาพ" ValidationGroup="Reg1">*</asp:RequiredFieldValidator>
		</td>
		<td>
			&nbsp;
		</td>
		<td>
			&nbsp;
		</td>
	</tr>
	<tr>
		<td colspan="4" style="text-align: right">
			<asp:Button ID="btnNext" runat="server" Text="ถัดไป >>" ValidationGroup="Reg1" OnClientClick="AlertUnder18Age()" />
			&nbsp;<asp:Button ID="btnLast" runat="server" Text="ไปหน้าสุดท้าย" Visible="False" />
			&nbsp;<asp:Button ID="btnCancel" runat="server" Text="ยกเลิก" />
		</td>
	</tr>
	<tr>
		<td colspan="4">
			<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="Reg1" />
		</td>
	</tr>
	<tr>
		<td>
			&nbsp;
		</td>
		<td>
			&nbsp;
		</td>
		<td>
			&nbsp;
		</td>
		<td>
			&nbsp;
		</td>
	</tr>
</table>
